﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShenLanCMS.Models;

namespace ShenLanCMS.Web.Controllers
{
    public class SiteinfoController : Controller
    {
        private EntityContext db = new EntityContext();

        //站点配置
        [IsAdmin]
        public ActionResult Index()
        {
            var siteid = Guid.Parse("9D4F258A-128E-4D84-99DF-AF5F030B9DE6");
            var siteinfo = db.Siteinfoes.SingleOrDefault(n => n.SiteinfoID == siteid);
            if (siteinfo == null)
            {
                try
                {
                    siteinfo = new Siteinfo();
                    siteinfo.SiteinfoID = siteid;
                    siteinfo.IsOpenAuthCode = true;
                    siteinfo.Description = "深蓝内容管理系统,ShenLanCMS";
                    siteinfo.Keyword = "深蓝内容管理系统,ShenLanCMS";
                    siteinfo.LogonOverTime = 30;
                    siteinfo.SiteMail = "admin@shenlanit.com";
                    siteinfo.SiteName = "深蓝内容管理系统";
                    siteinfo.SiteRecord = "桂ICP0000000号";
                    siteinfo.SiteUrl = "/";
                    db.Siteinfoes.Add(siteinfo);
                    db.SaveChanges();
                }
                catch
                {
                    siteinfo = new Siteinfo();
                    siteinfo.SiteinfoID = siteid;
                }
            }
            return View(siteinfo);

        }

        //站点配置
        [HttpPost]
        [IsAdmin]
        public ActionResult Index(Siteinfo siteinfo)
        {
            if (ModelState.IsValid)
            {
                db.Entry(siteinfo).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(siteinfo);
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}